/**
 * 
 */
package excelframe;

import java.awt.Color;
import java.io.File;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.filechooser.FileNameExtensionFilter;

/**
 * <p>Title:ExcelFrame</p>
 * <p>Description:TODO</p>
 * @author	xiongf
 * @date	2016年1月25日 上午11:14:27
 * @version 1.0
 */
public class ExcelFrame extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final int DEFAULT_WIDTH = 500;
	private static final int DEFAULT_HEIGHT = 400;
	private static final int DEFAUTL_POSITION_X = 200;
	private static final int DEFAULT_POSITION_Y = 200;

	public static File chooseFile;

	public ExcelFrame() {
		setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
		setLocation(DEFAUTL_POSITION_X, DEFAULT_POSITION_Y);
		setTitle("EBICS对账单账号导入");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	public File readFile() {
		JFileChooser chooser = new JFileChooser();
		chooser.setApproveButtonText("执行");
		int returnVal = chooser.showOpenDialog(this);
		// 过滤Excel文件，只寻找以xls结尾的Excel文件，如果想过滤word文档也可以写上doc
		FileNameExtensionFilter filter = new FileNameExtensionFilter("excel Files", "xls", "xlsx");
		chooser.setFileFilter(filter);
		if (returnVal == JFileChooser.APPROVE_OPTION) {
			chooseFile = chooser.getSelectedFile();
			ExcelParse.lblNewLabel_1.setText("");
		} else if (returnVal == JFileChooser.CANCEL_OPTION) {
			chooseFile = null;
			//ExcelParse.btnNewButton_1.setEnabled(false);
			ExcelParse.lblNewLabel_1.setForeground(Color.BLACK);
			ExcelParse.lblNewLabel_1.setText("");
		}
		return chooseFile;
	}

	public String getFilePath() {
		readFile();
		if (chooseFile != null) {
			String filePath = chooseFile.getAbsolutePath();
			return filePath;
		}
		return null;

	}

}
